﻿/// <reference path="math-utils.js" />
/// <reference group="Dedicated Worker" />
var isPrime = function (number) {
    for (var i = 2; i < number; i++) {
        if (number % i == 0) {
            return false;
        }
    }
    return true;
}

var calculatePrimesToNumber = function (toNumber) {
    var primesList = [];

    for (var num = 0; num <= toNumber; num++) {
        if (isPrime(num)) {
            primesList.push(num);
        }
    }

    return primesList;
}

onmessage = function (event) {
    var toNumber = event.data.toNumber;

    var primes = calculatePrimesToNumber(toNumber);

    postMessage(primes);
}
